package com.sum.tea.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.sum.common.bean.UHFDeviceType
import com.sum.common.inter.IUHFManager
import com.sum.common.manager.UHFManager

class LoadingViewModel : ViewModel() {
    private val _currentPage = MutableLiveData<Int>()
    val currentPage: LiveData<Int> = _currentPage

    private val _connectionStatus = MutableLiveData<Boolean>()
    val connectionStatus: LiveData<Boolean> = _connectionStatus

    private val _soundEnabled = MutableLiveData<Boolean>()
    val soundEnabled: LiveData<Boolean> = _soundEnabled

    // Reader相关
    fun connectReader() {
        UHFManager.getInstance().connect(object : UHFManager.ConnectCallback {
            override fun onSuccess(manager: IUHFManager?) {
                _connectionStatus.postValue(true)
            }

            override fun onFailed(error: String?) {
                _connectionStatus.postValue(false)
            }

        }, UHFDeviceType.ALL)
    }

    fun closeReader() {
        UHFManager.getInstance().close()
    }

    fun setCurrentPage(position: Int) {
        _currentPage.value = position
    }
}